package org.jugile.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Execute command line commands with args.
 * @author rahkojuk
 *
 */
public class Exec {

	public static void main(String args[]) {
		print(exec("cmd /C dir"));
		//print(exec("ls -la")); 
	}

	public static String exec(String cmd) {
		StringBuffer res = new StringBuffer();
		try {
			Process p = Runtime.getRuntime().exec(cmd);  
			BufferedReader in = new BufferedReader(  
					new InputStreamReader(p.getInputStream()));  
			String line = null;  
			while ((line = in.readLine()) != null) {  
				res.append(line + "\n");  
			}
		} catch (IOException e) {  
			e.printStackTrace();  
		}  		
		return res.toString();
	}
	
	public static void print(String msg) { System.out.println(msg); }
	
	
}
